<template>
	<view class="">
		<view class="group">
			<view class="group_title x-bc">
				<view class="left">{{group.length}}人在拼团，可直接参与</view>
				<view class="right pr" @tap.stop="open">
					<view class="text">查看全部</view>
					<image :src="arrow_right" mode=""></image>
				</view>
			</view>

			<view class="group_content">
				<view class="group_itme x-bc" v-for="(item, index) in groupList">
					<template v-for="(list, index) in item.memberList">
						<view class="left x-f" v-if="list.is_main == 1">
							<image :src="list.pic_url" mode=""></image>
							<view class="username">{{list.nickname}}</view>
						</view>
					</template>
					<view class="right">
						<view class="right_text tr">
							<view class="people">
								还差
								<text>{{item.group_max_member - item.group_number}}人</text>
								拼成
							</view>
							剩余
							<u-count-down class="time" :timestamp="item.endTime" color="#999999" font-size="22"
								height="36" separatorSize="22" separatorColor="#999999">
							</u-count-down>
						</view>
						<view class="right_btn">
							<button type="default" @tap="go_exchage(item)">参与拼团</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="group_bottom x-bc">
			<view class="left">开放拼团，成团发货，不成退款</view>
		</view>

		<popup ref="popup" :data="popup" @sure="sure"></popup>
		<popups ref="popups" :data="group" @go_group="go_group" @go_close="go_close"></popups>
	</view>
</template>

<script>
	export default {
		props: {
			group: {
				type: Array,
				default: null
			},
			groupList: {
				type: Array,
				default: null
			},
			isShowPopup: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				arrow_right: this.imgUrl + 'arrow_right.png', //向右图标
				avatar: this.imgUrl + 'after_sale-0.png',
				popup: {},
				popups: [],
			}
		},
		methods: {
			open() {
				this.$refs.popups.$data.show = true;
				this.$emit('openGroups')
			},
			// 拼团弹窗
			go_exchage(item) {
				this.popup = item;
				let obj = {
					pic_url: this.imgUrl + 'circle.png'
				}
				// 判断当前团的最大人数大于当前参加人数，则进行填充默认图片;
				if (this.popup.memberList.length < this.popup.group_max_member) {
					for (let i = this.popup.memberList.length; i < this.popup.group_max_member; i++) {
						this.popup.memberList.push(obj);
					}
				}
				this.popup.btn2 = '参与拼单';
				this.$refs.popup.$data.show = true;
			},
			sure() {
				this.$emit('popup')
			},
			go_group() {
				this.$emit('popups');
			},
			go_close() {
				this.$emit('go_close');
			}
		},
	}
</script>

<style lang="scss" scoped>
	.group {
		background: #fff;
		padding: 0 24rpx;

		.group_title {
			font-size: 24rpx;
			color: #333333;
			font-weight: 500;
			align-items: center;
			padding: 20rpx 0;

			.right {
				color: #A0A0A0;
				display: flex;
				line-height: 1em;
				align-items: center;

				image {
					width: 60rpx;
					height: 60rpx;
					vertical-align: middle;
				}
			}
		}

		.group_itme {
			font-size: 24rpx;
			border-top: 2rpx solid rgba($color: #DDD, $alpha: 0.5);

			.left {
				font-size: 28rpx;

				.username {
					padding-left: 12rpx;
					box-sizing: border-box;
					color: #333333;
					font-weight: 500;
				}

				image {
					width: 80rpx;
					height: 80rpx;
					border-radius: 50%;
				}
			}

			.right {
				display: flex;
				padding: 26rpx 0 22rpx 0;

				.right_text {
					padding-right: 20rpx;
					color: #999;

					text {
						color: #E93323;
					}
				}

				.right_btn {
					button {
						font-size: 24rpx;
						width: 154rpx;
						height: 56rpx;
						border-radius: 28rpx;
						color: #FFF;
						background-image: linear-gradient(to right, #ff2d1b, #ff977b);
					}
				}
			}
		}
	}

	.group_bottom {
		margin: 20rpx 0;
		padding: 25rpx 24rpx;
		box-sizing: border-box;
		font-size: 24rpx;
		color: #333333;
		font-weight: 500;
		background: #FFFFFF;

		.right {
			color: #A0A0A0;
			display: flex;
			line-height: 1em;
			align-items: center;

			image {
				width: 60rpx;
				height: 60rpx;
				vertical-align: middle;
			}
		}
	}
</style>
